project(compilation)

########################
## USE BISON AND FLEX ##
########################

find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)

include_directories(${FLEX_INCLUDE_DIRS})

bison_target(parser "./SimpleC.yy" "${CMAKE_CURRENT_BINARY_DIR}/SimpleC_gram.cpp"
  COMPILE_FLAGS "--debug -Wno-conflicts-sr")
flex_target(scanner "./SimpleC.lex" "${CMAKE_CURRENT_BINARY_DIR}/SimpleC_lex.cpp")
add_flex_bison_dependency(scanner parser)

######################
## GENERATE LIBRARY ##
######################

file(GLOB SOURCE
  "*.cpp"
  "*/*.cpp")
file(GLOB HEADER
  "${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME}/*.h*"
  "${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME}/*/*.h*"
  "*.h*"
  "*/*.h")

add_library(compilation
  ${HEADER} ${SOURCE}
  ${BISON_parser_OUTPUTS} ${FLEX_scanner_OUTPUTS})
target_link_libraries(compilation ${FLEX_LIBRARIES})

#################
## BUILD TESTS ##
#################

add_test_directory("test")
